package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.ShopCardVo;
import com.ruoyi.business.service.IShopCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 卡卷Controller
 *
 * @author Tellsea
 * @date 2025-01-19
 */
@Api(tags = "卡卷Controller")
@RestController
@RequestMapping("/business/card")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ShopCardController extends BaseController {

    private final IShopCardService shopCardService;

    @ApiOperation("查询卡卷列表")
    @PreAuthorize("@ss.hasPermi('business:card:list')")
    @GetMapping("/list")
    public TableDataInfo<ShopCardVo> list(ShopCardVo entity) {
        return shopCardService.queryList(entity);
    }

    @ApiOperation("查询卡卷所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ShopCardVo entity) {
        return AjaxResult.success("查询成功", shopCardService.queryAll(entity));
    }

    @ApiOperation("导出卡卷列表")
    @PreAuthorize("@ss.hasPermi('business:card:export')")
    @Log(title = "卡卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopCardVo entity) {
        List<ShopCardVo> list = shopCardService.queryAll(entity);
        ExcelUtil<ShopCardVo> util = new ExcelUtil<>(ShopCardVo.class);
        util.exportExcel(response, list, "卡卷数据");
    }

    @ApiOperation("获取卡卷详细信息")
    @PreAuthorize("@ss.hasPermi('business:card:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", shopCardService.queryById(id));
    }

    @ApiOperation("新增卡卷")
    @PreAuthorize("@ss.hasPermi('business:card:add')")
    @Log(title = "卡卷", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ShopCardVo entity) {
        return toAjax(shopCardService.save(entity));
    }

    @ApiOperation("修改卡卷")
    @PreAuthorize("@ss.hasPermi('business:card:edit')")
    @Log(title = "卡卷", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ShopCardVo entity) {
        return toAjax(shopCardService.updateById(entity));
    }

    @ApiOperation("删除卡卷")
    @PreAuthorize("@ss.hasPermi('business:card:remove')")
    @Log(title = "卡卷", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(shopCardService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }

//	@ApiOperation("导入卡卷")
//	@PreAuthorize("@ss.hasPermi('business:card:remove')")
//	@Log(title = "卡卷", businessType = BusinessType.DELETE)
//	@PostMapping("/upload")
//	public AjaxResult upload(@RequestParam("file") MultipartFile file) {
//		return shopCardService.upload(file);
//	}


}
